package tenumn.energytech;

import io.github.uicdb.liba.api.register.LazyRegistry;
import net.minecraft.client.particle.SnowflakeParticle;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.SlimeRenderer;
import net.minecraft.network.protocol.Packet;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.monster.Slime;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.network.NetworkHooks;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib3.GeckoLib;
import tenumn.energytech.registrys.*;
import tenumn.energytech.registrys.machine.MachineRegistry;
import tenumn.energytech.registrys.pipeline.WireRegistry;

import javax.annotation.Nonnull;

@Mod(EnergyTech.ID)
public class EnergyTech {
    public static final String NAME = "EnergyTech";
    public static final String ID = "energytech";
    public static final Logger LOGGER = LogManager.getLogger();
    public static final CreativeModeTab TAB_MAIN = new CreativeModeTab(ID) {
        @NotNull
        @Override
        public ItemStack makeIcon() {
            return new ItemStack(ItemRegistry.ENETE_BATTERY.get());
        }
    };
    public final static LazyRegistry LAZY_REGISTRY = new LazyRegistry(ID, TAB_MAIN);

    public EnergyTech() {
        MinecraftForge.EVENT_BUS.addListener(CapabilitiesRegistry::onRegisterCapabilities);
        GeckoLib.initialize();
        MachineRegistry.initialize();
        BlockRegistry.initialize();
        ItemRegistry.initialize();
        FluidRegistry.initialize();
        BlockEntityRegistry.initialize();
        MenuRegistty.initialize();
        ModLangRegistry.initialize();
        ModTagRegistry.initialize();
        WireRegistry.init();
        TierRegistry.init();
        TagRegistry.init();
        FeatureRegistry.init();
        RecipeRegistry.init();
        //只在客户端执行这部分代码
        DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> FMLJavaModLoadingContext.get().getModEventBus().addListener(MachineRegistry::clientSetup));
        DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> FMLJavaModLoadingContext.get().getModEventBus().addListener(ItemRegistry::clientSetup));
        LAZY_REGISTRY.mob("test",TestMob::new)
                .attributeLiving(()->Mob.createMobAttributes().add(Attributes.ATTACK_DAMAGE))
                .render(()->()->TestRender::new)
                .build();
       var test=LAZY_REGISTRY.particle("test",true)
                .build();
        LAZY_REGISTRY.runOnClient(()->{
            LAZY_REGISTRY.registerParticleFactory(test, ()->SnowflakeParticle.Provider::new);
        });

    }
    public static class TestMob extends Slime {

        protected TestMob(EntityType<? extends Slime> p_21368_, Level p_21369_) {
            super(p_21368_, p_21369_);
        }

        @Nonnull
        @Override
        public Packet<?> getAddEntityPacket() {
            return NetworkHooks.getEntitySpawningPacket(this);
        }
    }
    @OnlyIn(Dist.CLIENT)
    public static class TestRender extends SlimeRenderer{
        public TestRender(EntityRendererProvider.Context p_174391_) {
            super(p_174391_);
        }
    }


}